package Dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.Inflater;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import VO.AlterPlVO;
import VO.PLVO;
import VO.PlcAddVO;
import VO.PlcVO;

public class PlDao {
	
	private SqlSessionTemplate sqlTemplate;
	public void setSqlTemplate(SqlSessionTemplate sqlTemplate) {
		this.sqlTemplate = sqlTemplate;
	}
	public  void addPl(String pname){
	
		sqlTemplate.insert("p1.addPl",pname);
	
	}
	public List<PLVO> showPList(int page, int pageSize) {
		Map<String,Integer> map=new HashMap<String,Integer>();
		map.put("page",(page-1)*pageSize);
		map.put("pageSize", pageSize);
		
		return sqlTemplate.selectList("p1.showPList", map);
		
	}
	public int getAll() {
		return sqlTemplate.selectOne("p1.getAll");
		
	}
	public List<PlcVO> showPlInfo(int pid) {

		List<PlcVO> listPlcVO=sqlTemplate.selectList("p1.showPlInfo",pid);

		return listPlcVO;
	}
	public String showPlName(int pid) {
		System.out.println(pid);
		PLVO plvo=sqlTemplate.selectOne("p1.showPlName",pid);
		return plvo.getPname();
	}
	public void addPlc(List<PlcAddVO> listPlcAddVO) {
		
		sqlTemplate.insert("p1.addPlc",listPlcAddVO);
		
	}
	public void deletePl(int id) {
		sqlTemplate.delete("p1.deletePl",id);
		sqlTemplate.delete("p1.deletePlc",id);
		
	}
	public void alterPl(AlterPlVO alterPlVO) {
		sqlTemplate.update("p1.updatePl",alterPlVO);
		
	}
	

}
